home *** CD-ROM | disk | FTP | other *** search
/ Workbench Design / WB Collection.iso / workbench werkzeuge / memory & system tools / copymemquicker / source / testit.c < prev    next >
C/C++ Source or Header  |  1996-04-07  |  9KB  |  389 lines

  1. #include "testit.h"
  2.  
  3. void            *oldcms,
  4.             *newcms,
  5.             *oldcmq,
  6.             *newcmq,
  7.             *naught;
  8. char            *buf1,
  9.             *buf2,
  10.             *buf3,
  11.             *buf4;
  12. ULONG            identity;
  13. BOOL            negative;
  14.  
  15. void            *TimerBase;
  16. struct MsgPort        *tport;
  17. struct timerequest    *treq;
  18. struct timeval        tim1,
  19.             tim2,
  20.             tim3,
  21.             timold,
  22.             timdif,
  23.             totold,
  24.             totnew;
  25.  
  26. extern struct ExecBase    *SysBase;
  27.  
  28. #define S0_D0    0
  29. #define S0_D1    1
  30. #define    S0_D2    2
  31. #define    S0_D3    3
  32. #define    S1_D0    4
  33. #define    S1_D1    5
  34. #define    S1_D2    6
  35. #define    S1_D3    7
  36. #define    S2_D0    8
  37. #define    S2_D1    9
  38. #define    S2_D2    10
  39. #define    S2_D3    11
  40. #define    S3_D0    12
  41. #define    S3_D1    13
  42. #define    S3_D2    14
  43. #define    S3_D3    15
  44.  
  45. void printoffset(unsigned short alignment);
  46. #pragma regcall(printoffset(d0))
  47.  
  48. void testit(unsigned long loops,unsigned long bytes,long offset);
  49. #pragma regcall(testit(d0,d1,a0))
  50.  
  51. long main(void)
  52. {
  53. #asm
  54.     movea.l    (4).w,a0
  55.     move.l    _LVOCopyMem#+2(a0),a1
  56.     move.l    a1,_newcms
  57.     move.l    _LVOCopyMemQuick#+2(a0),_newcmq
  58.     move.l    -4(a1),_identity
  59.     move.l    -8(a1),_oldcms
  60.     move.l    -12(a1),_oldcmq
  61.     lea    _donaught#,a0
  62.     move.l    a0,_naught
  63. #endasm
  64.     if    (SysBase->LibNode.lib_Version < 37)
  65.     {
  66.         Write(Output(),"You need 2.0 to run this program!\n",34);
  67.         goto warn;
  68.     }
  69.     if    (identity != '*Art')
  70.     {
  71.         Printf("You must run CopyMemQuicker first!\n");
  72. warn:        return 5;
  73.     }
  74.     tport = CreatePort("cmemtest",0);
  75.     treq = (struct timerequest *)CreateExtIO(tport,(LONG)sizeof(struct timerequest));
  76.     OpenDevice("timer.device",UNIT_VBLANK,(struct IORequest *)treq,0);
  77.     TimerBase = treq->tr_node.io_Device;
  78.     Printf(    "This test will compare the old CopyMem/CopyMemQuick routines with\n"
  79.         "the new ones you have installed.  A great variety of tests will be\n"
  80.         "run, and this might take some time, especially if your system has a\n"
  81.         "slow processor.\n\n"
  82.         "Initiating test (please be patient...)\n\n");
  83.     if    ((!(buf1 = (char *)malloc(65540)))
  84.     ||    (!(buf2 = (char *)malloc(65540))))
  85.     {
  86.         Printf("Not enough memory to run test!\n");
  87.         return 10;
  88.     }
  89.  
  90.     {
  91.         UWORD    attnflags = SysBase->AttnFlags;
  92.         ULONG    scalefactor;
  93.  
  94.         if    (attnflags & AFF_68040)
  95.             scalefactor = 0;
  96.         else if    (attnflags & AFF_68030)
  97.             scalefactor = 1;
  98.         else if    (attnflags & AFF_68020)
  99.             scalefactor = 2;
  100.         else if    (attnflags & AFF_68010)
  101.             scalefactor = 3;
  102.         else    scalefactor = 4;
  103.  
  104.         testit(565 >> scalefactor,65536,S0_D0);
  105.         testit(147 >> scalefactor,65536,S0_D1);
  106.         testit(413 >> scalefactor,65536,S0_D2);
  107.         testit(147 >> scalefactor,65536,S0_D3);
  108.         testit(147 >> scalefactor,65536,S1_D0);
  109.         testit(382 >> scalefactor,65536,S1_D1);
  110.         testit(147 >> scalefactor,65536,S1_D2);
  111.         testit(501 >> scalefactor,65536,S1_D3);
  112.         testit(501 >> scalefactor,65536,S2_D0);
  113.         testit(147 >> scalefactor,65536,S2_D1);
  114.         testit(382 >> scalefactor,65536,S2_D2);
  115.         testit(147 >> scalefactor,65536,S2_D3);
  116.         testit(147 >> scalefactor,65536,S3_D0);
  117.         testit(413 >> scalefactor,65536,S3_D1);
  118.         testit(147 >> scalefactor,65536,S3_D2);
  119.         testit(564 >> scalefactor,65536,S3_D3);
  120.         testit(33900 >> scalefactor,1024,S0_D0);
  121.         testit(9400 >> scalefactor,1024,S0_D1);
  122.         testit(24000 >> scalefactor,1024,S2_D2);
  123.         testit(196000 >> scalefactor,128,S0_D0);
  124.         testit(155000 >> scalefactor,128,S2_D2);
  125.         testit(588000 >> scalefactor,19,S0_D0);
  126.         testit(622000 >> scalefactor,18,S0_D0);
  127.         testit(663000 >> scalefactor,17,S0_D0);
  128.         testit(956000 >> scalefactor,16,S0_D0);
  129.         testit(1060000 >> scalefactor,8,S0_D0);
  130.         testit(1430000 >> scalefactor,4,S0_D0);
  131.         testit(2190000 >> scalefactor,1,S0_D0);
  132.     }
  133.     free(buf2);
  134.     free(buf1);
  135.     Printf("Total timing:\n-------------\n");
  136.     Printf("%s routines    :%4ld.%02ld secs","Old",totold.tv_secs,totold.tv_micro / 10000);
  137.     Printf("\n");
  138.     Printf("%s routines    :%4ld.%02ld secs","New",totnew.tv_secs,totnew.tv_micro / 10000);
  139.     Printf("\n");
  140.     {
  141.         unsigned long    pctint,
  142.                 hund1,
  143.                 hund2;
  144.         struct timeval    *time3 = &tim3,
  145.                 *totalold = &totold;
  146.  
  147.         time3->tv_secs = totalold->tv_secs;
  148.         time3->tv_micro = totalold->tv_micro;
  149.         SubTime(time3,&totnew);
  150.         if    ((LONG)time3->tv_secs < 0)
  151.         {
  152.             time3->tv_secs = -((LONG)time3->tv_secs + 1);
  153.             time3->tv_micro = 1000000 - time3->tv_micro;
  154.             negative = TRUE;
  155.         }
  156.         else    negative = FALSE;
  157.         hund2 = (time3->tv_secs * 100) + (time3->tv_micro / 10000);
  158.         hund1 = (totalold->tv_secs * 100) + (totalold->tv_micro / 10000);
  159.         pctint = hund2 * 100000 / hund1;
  160.         if    ((pctint % 10) > 5)
  161.             pctint += 10;
  162.         pctint /= 10;
  163.         Printf("Total s%s\t:%4ld.%02ld %%   ",(negative) ? "lowdown" : "peedup",pctint / 100,pctint % 100);
  164.         Printf("\n");
  165.     }
  166.     CloseDevice((struct IORequest *)treq);
  167.     DeleteExtIO((struct IORequest *)treq);
  168.     DeletePort(tport);
  169.     return 0;
  170. }
  171.  
  172. #asm
  173.     xdef    _donaught
  174.     xdef    __cli_parse
  175.     xdef    __wb_parse
  176. _donaught:
  177. __cli_parse:
  178. __wb_parse:
  179.     rts
  180. #endasm
  181.  
  182. void printoffset(unsigned short alignment)
  183. {
  184.     Printf((alignment & 2) ? "even" : "long");
  185.     if    (alignment & 1)
  186.         Printf("+1");
  187. }
  188.  
  189. void testit(unsigned long loops,unsigned long bytes,long offset)
  190. {
  191.     struct timeval    *time1 = &tim1,
  192.             *time2 = &tim2,
  193.             *time3 = &tim3;
  194.     unsigned long    pctint;
  195.  
  196.     Printf("Copying %ld bytes %ld times (",bytes,loops);
  197.     buf3 = buf1 + ((offset & 0xC) >> 2);
  198.     buf4 = buf2 + (offset & 0x3);
  199.     printoffset((offset & 0xC) >> 2);
  200.     Printf(" -> ");
  201.     printoffset(offset & 0x3);
  202.     Printf(" offset)\n");
  203.  
  204.     Forbid();
  205.     GetSysTime(time1);
  206.     {
  207. #asm
  208.     movem.l    a2-a3/a6/d4-d5,-(sp)
  209.     movea.l    _naught,a2
  210.     movea.l    _buf3,a3
  211.     movea.l    _buf4,a6
  212.     move.l    %%loops,d4
  213.     move.w    d4,d5
  214.     swap    d4
  215.     subq.w    #1,d5
  216.     bcs.s    l1end
  217. loop1    movea.l    a3,a0
  218.     movea.l    a6,a1
  219.     move.l    %%bytes,d0
  220.     jsr    (a2)
  221.     dbf    d5,loop1
  222. l1end    dbf    d4,loop1
  223.     movem.l    (sp)+,a2-a3/a6/d4-d5
  224. #endasm
  225.     }
  226.     GetSysTime(time3);
  227.     Permit();
  228.  
  229.     SubTime(time3,time1);
  230.  
  231.     Forbid();
  232.     GetSysTime(time1);
  233.     {
  234. #asm
  235.     movem.l    a2-a3/a6/d4-d5,-(sp)
  236.     movea.l    _oldcms,a2
  237.     movea.l    _buf3,a3
  238.     movea.l    _buf4,a6
  239.     move.l    %%loops,d4
  240.     move.w    d4,d5
  241.     swap    d4
  242.     subq.w    #1,d5
  243.     bcs.s    l2end
  244. loop2    movea.l    a3,a0
  245.     movea.l    a6,a1
  246.     move.l    %%bytes,d0
  247.     jsr    (a2)
  248.     dbf    d5,loop2
  249. l2end    dbf    d4,loop2
  250.     movem.l    (sp)+,a2-a3/a6/d4-d5
  251. #endasm
  252.     }
  253.     GetSysTime(time2);
  254.     Permit();
  255.  
  256.     SubTime(time2,time1);
  257.     SubTime(time2,time3);
  258.     AddTime(&totold,time2);
  259.     timold.tv_secs = 
  260.     timdif.tv_secs = time2->tv_secs;
  261.     timold.tv_micro =
  262.     timdif.tv_micro = time2->tv_micro;
  263.     Printf("Old CopyMem%s: %2ld.%02ld secs\n","\t",time2->tv_secs,time2->tv_micro / 10000);
  264.  
  265.     Forbid();
  266.     GetSysTime(time1);
  267.     {
  268. #asm
  269.     movem.l    a2-a3/a6/d4-d5,-(sp)
  270.     movea.l    _newcms,a2
  271.     movea.l    _buf3,a3
  272.     movea.l    _buf4,a6
  273.     move.l    %%loops,d4
  274.     move.w    d4,d5
  275.     swap    d4
  276.     subq.w    #1,d5
  277.     bcs.s    l3end
  278. loop3    movea.l    a3,a0
  279.     movea.l    a6,a1
  280.     move.l    %%bytes,d0
  281.     jsr    (a2)
  282.     dbf    d5,loop3
  283. l3end    dbf    d4,loop3
  284.     movem.l    (sp)+,a2-a3/a6/d4-d5
  285. #endasm
  286.     }
  287.     GetSysTime(time2);
  288.     Permit();
  289.  
  290.     SubTime(time2,time1);
  291.     SubTime(time2,time3);
  292.     AddTime(&totnew,time2);
  293.     SubTime(&timdif,time2);
  294.     if    ((LONG)timdif.tv_secs < 0)
  295.     {
  296.         timdif.tv_secs = -((LONG)timdif.tv_secs + 1);
  297.         timdif.tv_micro = 1000000 - timdif.tv_micro;
  298.         negative = TRUE;
  299.     }
  300.     else    negative = FALSE;
  301.     Printf("New CopyMem%s: %2ld.%02ld secs","\t",time2->tv_secs,time2->tv_micro / 10000);
  302.     pctint    = ((timdif.tv_secs * 100) + (timdif.tv_micro / 10000)) * 10000
  303.         / ((timold.tv_secs * 100) + (timold.tv_micro / 10000));
  304.     if    ((pctint % 10) > 5)
  305.         pctint += 10;
  306.     pctint /= 10;
  307.     Printf(" (%s%2ld.%ld%%)\n",(negative) ? "+" : "-",pctint / 10,pctint % 10);
  308.     if    ((!offset) && (!(bytes % 4)))
  309.     {
  310.     Forbid();
  311.     GetSysTime(time1);
  312.     {
  313. #asm
  314.     movem.l    a2-a3/a6/d4-d5,-(sp)
  315.     movea.l    _oldcmq,a2
  316.     movea.l    _buf3,a3
  317.     movea.l    _buf4,a6
  318.     move.l    %%loops,d4
  319.     move.w    d4,d5
  320.     swap    d4
  321.     subq.w    #1,d5
  322.     bcs.s    l4end
  323. loop4    movea.l    a3,a0
  324.     movea.l    a6,a1
  325.     move.l    %%bytes,d0
  326.     jsr    (a2)
  327.     dbf    d5,loop4
  328. l4end    dbf    d4,loop4
  329.     movem.l    (sp)+,a2-a3/a6/d4-d5
  330. #endasm
  331.     }
  332.     GetSysTime(time2);
  333.     Permit();
  334.  
  335.     SubTime(time2,time1);
  336.     SubTime(time2,time3);
  337.     AddTime(&totold,time2);
  338.     timold.tv_secs = 
  339.     timdif.tv_secs = time2->tv_secs;
  340.     timold.tv_micro =
  341.     timdif.tv_micro = time2->tv_micro;
  342.     Printf("Old CopyMem%s: %2ld.%02ld secs\n","Quick",time2->tv_secs,time2->tv_micro / 10000);
  343.  
  344.     Forbid();
  345.     GetSysTime(time1);
  346.     {
  347. #asm
  348.     movem.l    a2-a3/a6/d4-d5,-(sp)
  349.     movea.l    _newcmq,a2
  350.     movea.l    _buf3,a3
  351.     movea.l    _buf4,a6
  352.     move.l    %%loops,d4
  353.     move.w    d4,d5
  354.     swap    d4
  355.     subq.w    #1,d5
  356.     bcs.s    l5end
  357. loop5    movea.l    a3,a0
  358.     movea.l    a6,a1
  359.     move.l    %%bytes,d0
  360.     jsr    (a2)
  361.     dbf    d5,loop5
  362. l5end    dbf    d4,loop5
  363.     movem.l    (sp)+,a2-a3/a6/d4-d5
  364. #endasm
  365.     }
  366.     GetSysTime(time2);
  367.     Permit();
  368.  
  369.     SubTime(time2,time1);
  370.     SubTime(time2,time3);
  371.     AddTime(&totnew,time2);
  372.     SubTime(&timdif,time2);
  373.     if    (negative = ((LONG)timdif.tv_secs < 0))
  374.     {
  375.         timdif.tv_secs = -((LONG)timdif.tv_secs + 1);
  376.         timdif.tv_micro = 1000000 - timdif.tv_micro;
  377.     }
  378.     Printf("New CopyMem%s: %2ld.%02ld secs","Quick",time2->tv_secs,time2->tv_micro / 10000);
  379.     pctint    = ((timdif.tv_secs * 100) + (timdif.tv_micro / 10000)) * 10000
  380.         / ((timold.tv_secs * 100) + (timold.tv_micro / 10000));
  381.     if    ((pctint % 10) > 5)
  382.         pctint += 10;
  383.     pctint /= 10;
  384.     Printf(" (%s%2ld.%ld%%)\n",(negative) ? "+" : "-",pctint / 10,pctint % 10);
  385.     }
  386.     Printf("\n");
  387. }
  388.  
  389.